package com.spacing.app;
import java.util.Arrays;

import android.app.Activity;
import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;

import com.androidplot.series.XYSeries;
import com.androidplot.xy.LineAndPointFormatter;
import com.androidplot.xy.SimpleXYSeries;
import com.androidplot.xy.XYPlot;
import com.senseilearning.anatomy.R;

/**
 * The simplest possible example of using AndroidPlot to plot some data.
 */
public class PlotActivity extends Activity
{

    private XYPlot mySimpleXYPlot;

    @Override
    public void onCreate(Bundle savedInstanceState)
    {

        super.onCreate(savedInstanceState);
        setContentView(R.layout.plot);

        // initialize our XYPlot reference:
        mySimpleXYPlot = (XYPlot) findViewById(R.id.mySimpleXYPlot);

        // Create a couple arrays of y-values to plot:
        Intent intent = getIntent();
		double [] x_i = (double []) intent.getSerializableExtra("x");
		double [] y_i = (double []) intent.getSerializableExtra("y");
        
		Number[] x = getNumbers(x_i); 
		Number[] y = getNumbers(y_i);
		
        // Turn the above arrays into XYSeries':
        XYSeries series1 = new SimpleXYSeries(
                Arrays.asList(x),          // SimpleXYSeries takes a List so turn our array into a List
                Arrays.asList(y), // Y_VALS_ONLY means use the element index as the x value
                "Series1");                             // Set the display title of the series

        // same as above
        //XYSeries series2 = new SimpleXYSeries(Arrays.asList(y), SimpleXYSeries.ArrayFormat.Y_VALS_ONLY, "Series2");

        // Create a formatter to use for drawing a series using LineAndPointRenderer:
        LineAndPointFormatter series1Format = new LineAndPointFormatter(
                Color.rgb(0, 200, 0),                   // line color
                Color.rgb(0, 100, 0),                   // point color
                null);                                  // fill color (none)

        // add a new series' to the xyplot:
        mySimpleXYPlot.addSeries(series1, series1Format);

        // same as above:
       // mySimpleXYPlot.addSeries(series2,
         //       new LineAndPointFormatter(Color.rgb(0, 0, 200), Color.rgb(0, 0, 100), null));

        // reduce the number of range labels
        mySimpleXYPlot.setTicksPerRangeLabel(3);

        // by default, AndroidPlot displays developer guides to aid in laying out your plot.
        // To get rid of them call disableAllMarkup():
        mySimpleXYPlot.disableAllMarkup();
    }
    
    private Number[] getNumbers(double[] a){
    	Number [] b =  new Number [a.length];
    	
    	for (int i =0; i< a.length;i++){
    		b[i] = a[i];
    		
    	}
    	
    	return b;
    }
    
}